#include "ansi_interface.h"

#define ANSI_INTERFACE_H__

extern DMInt32u getNowSeconds();

DMInt32u get_current_time(void)
{
	return getNowSeconds();
}

void msleep(DMInt32u msec)
{
	ApiSleep(msec);
}

void nsleep(DMInt32u usec)
{
	usleep(usec);
}

unsigned short ansi_htons(unsigned short n)
{	/*! 高低位交换 */
	return ((n & 0xff) << 8) | ((n & 0xff00) >> 8);
}

int32_t ansi_meter_prefetch(uint8_t port, uint8_t *buf, uint32_t size)
{
	DMUartInfo * pUartInfo = g_getUart(port);
	return ApiUartPrefetch(pUartInfo, buf, size);
}

int32_t ansi_meter_read(uint8_t port, uint8_t *buf, uint32_t len)
{
	DMUartInfo * pUartInfo = g_getUart(port);

	return ApiUartRead(pUartInfo, buf, len);
}

void ansi_meter_write(uint8_t port, uint8_t *buf, uint32_t len)
{
	DMUartInfo * pUartInfo = g_getUart(port);

	ApiUartWrite(pUartInfo, buf, len);
}

void ansi_meter_flush(uint8_t port)
{
	DMUartInfo * pUartInfo = g_getUart(port);
	ApiUartClear(pUartInfo);
}

//todo 待增加配置
void ansi_meter_init(uint8_t port)
{
	DMUartInfo * pUartInfo = g_getUart(port);

	ApiUartSetParameters(pUartInfo, 1200, 8, 0, 1);

	ApiUartClear(pUartInfo);
}